<template>
	<view class="content">
		
		<u-row justify="center" custom-style="marginTop:32px;">
			<u-col justify="center" span="12" offset="10">
				<u--image :showLoading="true" :src="sfyLogo" width="60px" height="60px" shape="circle"></u--image>
			</u-col>
		</u-row>
			
		<u-row justify="center" custom-style="marginTop:32px;  ">
			<u-col justify="center" span="12" offset="9">
				<text style="font-size: 12px;">欢迎使用三法印系统 </text>
			</u-col>
		</u-row>
	
		
		<view style="margin-top: 8px;"></view>
		<u-button type="success" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">手机号快捷登录</u-button>
	</view>
</template>

<script>
	import {login,handleLoginStorage} from '@/api/auth.js'
	export default{
		data(){
			return {
				sfyLogo:"/static/logo.png",
				phoneLoginForm:{
					encryptedData:undefined,
					iv:undefined,
					code:undefined
				}
			}
		},
		methods:{
			getPhoneNumber(e){
				 uni.showLoading({
					mask: true,
					title: '加载中'
				 });
				 if (e.detail.encryptedData) {
					this.phoneLoginForm.encryptedData=e.detail.encryptedData;
					this.phoneLoginForm.iv = e.detail.iv;
					this.loginByPhone();
				 }else{
					 uni.hideLoading();
				 }
								 
			},
			loginByPhone(){
			 let that=this;
			 uni.login({
				 provider: 'weixin',
				 success: (res) => {
					if (res.code) {
						that.phoneLoginForm.code = this.$u.trim(res.code);
						login(this.phoneLoginForm).then(res=>{
							
							if(res.code==200){
								that.$store.commit("setToken",res.data.loginToken);
								console.log(res.data);
								handleLoginStorage(res.data);
								// uni.navigateBack();
								uni.reLaunch({
									url:'/pages/index/index'
								})
								
							}
							uni.hideLoading();
						}).catch(err=>{
							uni.hideLoading();
						});
						
					} else {
						console.log('登录失败！' + res.errMsg)
						uni.hideLoading();
					}
				 }
			 });
			},
		}
	}
</script>

<style>
</style>